package com.itboye.zhujia.base;

import java.lang.ref.WeakReference;
import java.util.LinkedList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.Application;
import android.app.Notification;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.app.NotificationCompat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.RemoteViews;
import android.widget.Toast;

import com.itboye.zhujia.R;
import com.squareup.picasso.Picasso;

public class MyApplcation extends Application{

		public static MyApplcation ctx;

		private Toast toast;

		private List<WeakReference<Activity>> activityList = new LinkedList<>();

		protected String afterOpen;

		protected String activity;

		protected String extra;

		protected org.json.JSONObject jsonObject2;

		protected String afterOpen2;
		String baseUrl = "http://sunsun.itboye.com/index.php/Webview/index/systemMessage?";

		protected String order_code;

		protected String id;

		protected int type;

		protected JSONObject jsonObject;
		boolean isReadOne, isReadTwo;
		
		// private List<WeakReference<Activity>> activitys = new
		// ArrayList<WeakReference<Activity>>();

		// private UncaughtExceptionHandler exceptionHandler;
		public static MyApplcation getInstance() {
			return ctx;
		}

		@Override
		public void onCreate() {
			// TODO Auto-generated method stub
			super.onCreate();

			ctx = this;
		}


		public void showNetWorkError() {
			if (toast == null) {
				toast = Toast.makeText(MyApplcation.ctx, "", 1);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.setView(LayoutInflater.from(MyApplcation.ctx).inflate(
						R.layout.dialog_network_error, null));
			}

			toast.show();
		}

		public void addActivity(Activity activity) {
			activityList.add(new WeakReference<Activity>(activity));
		}

		// 遍历所有Activity并finish
		public void exit() {
			for (WeakReference<Activity> activity : activityList) {
				if (activity.get() != null) {
					activity.get().finish();
				}

			}
			System.exit(0);
		}


}
